/*
 *  蓝肽子序列 国赛A组c++ dp问题
 * */

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

vector<vector<int>> dp(1005, vector<int>(1005, 0));
string s1, s2;
string str1[1005], str2[1005];

int main() {
    cin >> s1 >> s2;

    auto size1 = s1.length(), size2 = s2.length();
    int str1_size = 0, str2_size = 0;

    for (int i = 0; i < size1;) {
        str1_size++;
        str1[str1_size] += s1[i++];
        while (s1[i] >= 'a' && s1[i] <= 'z') {
            str1[str1_size] += s1[i++];
        }
    }

    for (int i = 0; i < size2;) {
        str2_size++;
        str2[str2_size] += s2[i++];
        while (s2[i] >= 'a' && s2[i] <= 'z') {
            str2[str2_size] += s2[i++];
        }
    }


    // 开始去遍历子序列
    for (int i = 1; i <= str1_size; ++i) {
        for (int j = 1; j <= str2_size; ++j) {
            if (str1[i] == str2[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    cout << dp[str1_size][str2_size] << endl;

    return 0;
}